package com.mvc4g.example.client.company.views;

import com.google.gwt.user.client.ui.TextBox;
import com.mvc4g.client.Event;
import com.mvc4g.example.client.company.CompanyBean;

public class CreateCompanyView extends AbstractCompanyView {

	private TextBox name = null;
	private TextBox address = null;
	
	protected void finishCreation(){
		name = new TextBox();
		address = new TextBox();
		grid.setWidget(0, 1, name);
		grid.setWidget(1, 1, address);
	}

	public void init(CompanyBean company) {
		if(company != null){
		name.setText(company.getName());
		address.setText(company.getAddress());
		}
		else{
			name.setText(EMPTY_STRING);
			address.setText(EMPTY_STRING);
		}
	}

	protected String getButtonText() {
		return "Create";
	}

	protected void buttonAction() {
		CompanyBean company = new CompanyBean();
		company.setName(name.getText());
		company.setAddress(address.getText());
		controller.handleEvent(new Event(CREATE_COMPANY, company));
	}

}
